var TcFollowTableList = {// 医生回访表格初始化
    id: "TcFollowTableListReservations",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

function _cellStyles(value, row, index) {
    if (row.revisitStatus == 2) {
        return {
            css: {"background-color": "#fff1d5", "overflow": "hidden", "white-space": "nowrap", "text-overflow": "ellipsis"}
        }
    } else {
        return {css: {"overflow": "hidden", "white-space": "nowrap", "text-overflow": "ellipsis"}}
    }
}

TcFollowTableList.initColumn = function () {//初始化表格的列
    var columns = [
        {title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle'},
        {title: 'customerId', field: 'customerId', visible: false, align: 'center', valign: 'middle'},
        {title: '诊所', field: 'arrivalStore', align: 'center', valign: 'middle', sortable: true,width:50,
            cellStyle: function (value, row, index) {
                return _cellStyles(value, row, index);
            }
        },
        {title: '回访人员', field: 'revisit', align: 'center', valign: 'middle', sortable: true,width:100,
            cellStyle: function (value, row, index) {
                return _cellStyles(value, row, index);
            }
        },
        {title: '跟踪状态', field: 'followStatus', align: 'center', valign: 'middle', sortable: true,width:100,
            cellStyle: function (value, row, index) {
                return _cellStyles(value, row, index);
            }
        },
        {title: '消费状态', field: 'consumptionStatus', align: 'center', valign: 'middle', sortable: true,width:100,
            cellStyle: function (value, row, index) {
                return _cellStyles(value, row, index);
            }
        },
        {title: '回访内容', field: 'remarks', align: 'center', valign: 'middle', sortable: true,width:110,
            cellStyle: function (value, row, index) {
                return _cellStyles(value, row, index);
            }
        },
        {title: '回访结果', field: 'revisitContent', align: 'center', valign: 'middle', sortable: true,width:110,
            cellStyle: function (value, row, index) {
                return _cellStyles(value, row, index);
            }
        },
        {
            title: '回访状态', field: 'revisitStatus', align: 'center', valign: 'middle', sortable: true, width: 100,
            formatter: function (value, row, index) {
                if (value == 1) {
                    return "<span>" + "待计划" + "</span>"
                } else if (value == 2) {
                    return "<span>" + "回访完成" + "</span>"
                } else if (value == 3) {
                    return "<span>" + "回访未完成" + "</span>"
                } else if (value == 4) {
                    return "<span>" + "回访取消" + "</span>"
                }
            },
            cellStyle: function (value, row, index) {
                return _cellStyles(value, row, index);
            }
        },

        {title: '计划回访时间', field: 'revisitTime', align: 'center', valign: 'middle', sortable: true,width:100,
            formatter: function (value, row, index) {
                return value.substring(0, 11);
            },
            cellStyle: function (value, row, index) {
                return _cellStyles(value, row, index);
            }
        },
        {
            title: '创建时间', field: 'createTime', align: 'center', valign: 'middle', sortable: true, width: 100,
            formatter: function (value, row, index) {
                return value.substring(0, 11);
            },
            cellStyle: function (value, row, index) {
                return _cellStyles(value, row, index);
            }
        },
        {
            title: '完成时间', field: 'updateTime', align: 'center', valign: 'middle', sortable: true, width: 100,
            formatter: function (value, row, index) {
                return value.substring(0, 11);
            },
            cellStyle: function (value, row, index) {
                return _cellStyles(value, row, index);
            }
        }
    ];
    return columns;
};

TcFollowTableList.check = function () {// 检查是否选中
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        TcFollowTableList.seItem = selected[0];
        return true;
    }
};

TcFollowTableList.deletefollowRevision = function (ids) {//删除回访
    if (confirm("确认删除本条回访？")) {
        $.ajax({
            url: Feng.ctxPath + "/tcRevisit/delete_tcFollow",
            type: "post",
            data: {
                ids:ids
            },
            success: function (data) {
                Feng.success('操作成功!');
                window.TcFollowTableList.search();
            },
            error: function (data) {
                alert('没有权限，请联系管理员!');
            }
        });
    }
};

TcFollowTableList.followRevision = function (ids) {//编辑回访
    var index = layer.open({
        type: 2,
        title: '回访',
        area: ['60%', '100%'], //宽高
        fix: true, //不固定
        maxmin: true,
        offset: ['0px', '40%'],
        content: Feng.ctxPath + '/tcRevisit/tc_followss/' + ids
    });
    this.layerIndex = index;
};

TcFollowTableList.lookfollowListRevision = function (ids) {//查看回访
    var index = layer.open({
        type: 2,
        title: '回访',
        area: ['60%', '100%'], //宽高
        fix: true, //不固定
        maxmin: true,
        offset: ['0px', '40%'],
        content: Feng.ctxPath + '/tcRevisit/tc_lookfollowList/' + ids
    });
    this.layerIndex = index;
};


TcFollowTableList.search = function () {
    TcFollowTableList.table.refresh();
};

$(function () {

});